package com.mobilous.client.project.menu;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.ToggleButton;
import com.mobilous.client.StaticData;
import com.mobilous.client.MainScreen.MainPage;
import com.mobilous.client.project.pagemanager.ApplicationPages;

public class MenuItems extends Composite {
	ToggleButton tglbtnPages;
	ToggleButton tglbtnResources;
	ToggleButton tglbtnAppSettings;
	ToggleButton tglbtnDatasources;
	
	public MenuItems() {
    	AbsolutePanel absolutePanelMenuBar = new AbsolutePanel();
		initWidget(absolutePanelMenuBar);
		absolutePanelMenuBar.setStyleName("gwt-background");
		absolutePanelMenuBar.setSize("1024px", "45px");
		
		tglbtnPages = new ToggleButton("Pages");
		absolutePanelMenuBar.add(tglbtnPages, 99, 10);
		
		tglbtnResources = new ToggleButton("Resources");
		absolutePanelMenuBar.add(tglbtnResources, 154, 10);
		
		tglbtnAppSettings = new ToggleButton("App Settings");
		absolutePanelMenuBar.add(tglbtnAppSettings, 234, 10);
		
		tglbtnDatasources = new ToggleButton("Datasources");
		absolutePanelMenuBar.add(tglbtnDatasources, 327, 10);
		
		Image image = new Image("images/helpicon.png");
		absolutePanelMenuBar.add(image, 982, 10);
		image.setSize("32px", "32px");
		
		PushButton pushButton = new PushButton("< Back");
		absolutePanelMenuBar.add(pushButton, 10, 10);
		//first start
		enableAllButton();
		tglbtnPages.setDown(true);
		tglbtnPages.setEnabled(false);

		//Back Button Action
		pushButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				StaticData.absolutePanelMainBody.clear();
				StaticData.absolutePanelMenuBar.clear();
				new MainPage();
			}
		});
		
		//Pages Button Pressed.
		tglbtnPages.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				StaticData.absolutePanelMainBody.clear();
				enableAllButton();
				tglbtnPages.setDown(true);
				tglbtnPages.setEnabled(false);
				StaticData.absolutePanelMainBody.add(new ApplicationPages());
			}
		});
		
		tglbtnResources.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				StaticData.absolutePanelMainBody.clear();
				enableAllButton();
				tglbtnResources.setDown(true);
				tglbtnResources.setEnabled(false);
				
			}
		});
		
		tglbtnAppSettings.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				StaticData.absolutePanelMainBody.clear();
				enableAllButton();
				tglbtnAppSettings.setDown(true);
				tglbtnAppSettings.setEnabled(false);
				
			}
		});
		
		tglbtnDatasources.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				StaticData.absolutePanelMainBody.clear();
				enableAllButton();
				tglbtnDatasources.setDown(true);
				tglbtnDatasources.setEnabled(false);
				
			}
		});
	}
	
	void enableAllButton()
	{
		tglbtnPages.setDown(false);
		tglbtnResources.setDown(false);
		tglbtnAppSettings.setDown(false);
		tglbtnDatasources.setDown(false);
		
		tglbtnPages.setEnabled(true);
		tglbtnResources.setEnabled(true);
		tglbtnAppSettings.setEnabled(true);
		tglbtnDatasources.setEnabled(true);
	}
	
}
